<?php

    /**
     * Fech results from cms DB
     */
    class cms extends CI_Model {

        public function all_posts($parent_ID = NULL, $post_type = 'page') {

            $binding = array($post_type);

            $sql = "SELECT * FROM posts_pic_seo WHERE post_type = ? ";

            if (isset($parent_ID)):
                $sql.=" AND parent_ID = ? ";
                $binding[] = $parent_ID;

            endif;


            $res = $this->db->query($sql, $binding);

            return $res->result_array();
        }

        public function get_post($ID) {

            $sql = "SELECT * FROM posts_pic_seo WHERE ID = ? ";

            $res = $this->db->query($sql, array($ID));

            return $res->row_array();
        }

        public function get_pictures($post_ID) {

            $sql = "SELECT * FROM pic_gallery WHERE post_ID = ? ";

            $res = $this->db->query($sql, array($post_ID));

            return $res->result_array();
        }

        public function get_files($post_ID) {

            $sql = "SELECT * FROM files_folders WHERE post_ID = ? ";

            $res = $this->db->query($sql, array($post_ID));

            return $res->result_array();
        }

    }

?>
